package com.dzu.easy;

/**
 * @author ZhaoDong
 * @date 2022/10/27 10:12
 * @description 415. 字符串相加
 */
public class Test415 {
    public static void main(String[] args) {

        System.out.println(addStrings("456", "77"));
    }


    public static String addStrings(String num1, String num2) {

        StringBuffer sb = new StringBuffer();
        int jinwei = 0;
        for (int i = num1.length() - 1, j = num2.length() - 1; i >= 0 || j >= 0; i--, j--) {
            int sum = jinwei;
            sum += i >= 0 ? num1.charAt(i) - '0' : 0;
            sum += j >= 0 ? num2.charAt(j) - '0' : 0;
            sb.append(sum % 10);
            jinwei = sum / 10;

        }
        sb.append(jinwei == 1 ? 1 : "");
        return sb.reverse().toString();

    }


}
